package com.example.demo;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class RedisTemp {

	public static RedisTemplate<String, String> template;

	@Autowired
	public RedisTemp(RedisTemplate<String, String> template) {
		super();
		RedisTemp.template = template;
	}
	
	
	public static void set(String key, String value) {
		template.opsForValue().set(key, value);
	}
	
	public static String get(String key) {
		return template.opsForValue().get(key);
	}
	
	public static boolean del(String key) {
		if(template.hasKey(key))
			return template.delete(key);
		else
			return false;
	}
	
	public static boolean existsKey(final String key) {
		return template.hasKey(key);
	}
	
	/* set ops  */
	
	public static Long setadd(String key, String... values) {
		return template.opsForSet().add(key, values);
	}
	
	public static Set<String> setGet(String key) {
		return template.opsForSet().members(key);
	}
	
	public static Long setDelete(String key, String... values) {
		Long l = template.opsForSet().remove(key, values);
		return l;
	}
	
	public static Long setSize(String key) {
		return template.opsForSet().size(key);
	}
}
